#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define DEVNAME "/sys/devices/platform/led_ctrl/gpio_led"

//主函数main
int main(int argc, char** argv)
{
	int fd;
	int len;
	char on[] = "1";
	char off[] = "0";

	printf("%s(), __%d__\n", __func__, __LINE__);

	while(1) {
		fd = open(DEVNAME, O_RDWR | O_NONBLOCK); //打开设备节点,
		if(fd<0){
			printf("open device error\n");
		}
		len = write(fd, on, sizeof(on));
		printf("pull up gpio, green led\n");
		if (len < 0) {
			printf("write data error \n");
		}

		sleep(1);

		len = write(fd, off, sizeof(off));
		printf("pull down gpio, red led\n");
		if (len < 0) {
			printf("write data error \n");
		}
		sleep(1);
	}
	close(fd); //关闭设备

        return 0;
}
